package cn.yangliu.nacos.management.web.sys;

import cn.yangliu.jpa.handler.JpaHandler;
import cn.yangliu.nacos.comm.config.security.annotations.Authorize;
import cn.yangliu.nacos.management.entity.sys.Operation;
import cn.yangliu.nacos.management.model.OperationQueryModel;
import cn.yangliu.nacos.management.service.sys.OperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * The type of nacos.
 *
 * @author 问道于盲
 * @date 2020 -01-04
 */
@RestController
@Api(tags = "操作日志")
@RequestMapping("/sys/operation")
public class OperationController {

    /**
     * current class instance's member.
     * The Operation service.
     */
    @Autowired
    private OperationService operationService;

    /**
     * current class instance's member.
     * The Jpa handler.
     */
    private JpaHandler jpaHandler = JpaHandler.INSTANCE;

    /**
     * Page page.
     *
     * @param model the model
     * @return the page
     */
    @GetMapping("/page")
    @ApiOperation("条件分页查询操作日志")
    @Authorize("operation:query")
    public Page<Operation> page(OperationQueryModel model) {
        Specification<Operation> specification = jpaHandler.buildSpecification(model);
        return operationService.findAll(specification, model.build());
    }
}
